package service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import dao.IGoodsDao;
import model.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import service.IGoodsService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class GoodsService implements IGoodsService {
    @Autowired
    private IGoodsDao iGoodsDao;

    @Override
    public List<Goods> list(Goods goods) {
        return  iGoodsDao.query(goods);
    }

    @Override
    public int totalCount(Goods goods) {
        return  iGoodsDao.totalCount(goods);
    }

    @Override
    public List<Goods> selectParentId(Goods goods) {
        return  iGoodsDao.selectParentId(goods);
    }

    @Override
    public String selectSortId(Goods goods) {
        List<Goods> list= iGoodsDao.selectSortId(goods);
        JSONArray arr = new JSONArray();
        for (Goods sortId : list) {
            System.out.println(sortId.getsName());
            //创建json对象
            JSONObject obj = new JSONObject();
            //添加键值对
            obj.put("sortId", sortId.getSortId());
            obj.put("sName", sortId.getsName());
            arr.add(obj);
        }
        return arr.toString();
    }

    @Override
    public List<Goods> sort(Goods goods) {
        return  iGoodsDao.selectSortId(goods);
    }

    @Override
    public int update(Goods goods) {
        return  iGoodsDao.update(goods);
    }

    @Override
    public int insert(Goods goods) {
        return  iGoodsDao.insert(goods);
    }

    @Override
    public List<Goods> queryOff(Goods goods) {
        return  iGoodsDao.queryOff(goods);
    }

    @Override
    public int totalCountOff(Goods goods) {
        return iGoodsDao.totalCountOff(goods);
    }

    @Override
    public int updateStatus(Map<String,String> map) {

        return iGoodsDao.updateStatus(map);
    }


}
